<?php

namespace app\index\model;

use think\Model;
use think\Session;
use app\common\traits\model\TraitModel;
use \app\common\traits\model\UserOperateCheck;

class CaravanInfos extends Model
{
    use TraitModel;
    protected $autoWriteTimestamp = 'timestamp';
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';
    protected $table = 'caravan';
    protected $type = [
            'piccaravan'=>'array',
            'caravancover'=>'array'
    ];

    public function camps()
    {
        return $this->belongsTo('Camps','services');
    }

    public function test()
    {
        return $this->hasMany('Filters','caravan_id');
    }

    public function getCaravanInfo($caravan_id = null, $field = '')
    {
      empty($user_id) && $user_id = self::getLoginUserInfo('id');
      $caravanInfo = self::get(['id' => $caravan_id]);
      if ($field) {
          if (isset($caravanInfo->$field)) {
              return $caravanInfo->$field; 
          }
          return ;
      }
      return $caravanInfo;
    }
    //房车类型---房车品牌---房车国别---准驾类型--档位类型-------->字段转换
    /**
     * [getGrade 类型转换]
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function getCates($id)
    {
        $grades = db('car_cates')->column('name', 'id');
        if (array_key_exists($id, $grades)) {
           return $grades[$id];
        }
        return '无';
    }
    public function getBrands($id)
    {
        $grades = db('car_brands')->column('name', 'id');
        if (array_key_exists($id, $grades)) {
           return $grades[$id];
        }
        return '无';
    }
    public function getCountries($id)
    {
        $grades = db('car_countries')->column('name', 'id');
        if (array_key_exists($id, $grades)) {
           return $grades[$id];
        }
        return '无';
    }
    public function getDrtypes($id)
    {
        $grades = db('driver_types')->column('name', 'id');
        if (array_key_exists($id, $grades)) {
           return $grades[$id];
        }
        return '无';
    }
    public function getZiduan3Name($value)
    {
        $status = ['1'=>'手动挡','2'=>'自动挡','3'=>'手自一体'];
        return $status[$value];
    }
    public function getRadioName($value)
    {
    	if(empty($value)){
    		return '无';
    	}
        $status = ['1'=>'有','2'=>'无'];
        return $status[$value];
    }
    
}
